///<reference path="../typings/index.d.ts"/>
import redis = require("redis");
// const redisClient = redis.createClient({ host: "127.0.0.1", port: 6379 });
// const redisSubClient = redis.createClient({ host: "127.0.0.1", port: 6379 });
const redisClient = redis.createClient({ host: "127.0.0.1", port: 6379 });
const redisSubClient =redis.createClient({ host: "127.0.0.1", port: 6379 });
const redisTradeClient = redis.createClient({ host: "127.0.0.1", port: 6379 });
redisClient.auth("xinbaby");
redisSubClient.auth("xinbaby");
redisTradeClient.auth("xinbaby");
redisClient.on("connect", () => {
    console.log("redis connected");
});
redisClient.on("error", (err) => {
    console.log("redis errror " + err);
});
export class RedisAction {
    test() {


        setInterval(() => {
            redisClient.publish("order", '{"Login":3117,"ManagerAccount":3112,"Symbol":"GBPUSD","Volume":1,"CMD":0,"Ticket":518,"Action":0}');
        }, 2000);

        redisSubClient.subscribe("reject", (chan, message) => {
            console.log(message);
        });
        redisSubClient.subscribe("log");
        redisSubClient.on("message", (chan, message) => {
            console.log(message);
            if(chan == "reject"){
            redisTradeClient.get(message, (err, data) => {
                if (!err) {
                    console.log(data);
                }
            });
        }
        });
        //  var sendrresult = redisClient.publish("test", "thisi is a test");
        //  redisClient.publish("test", "wang zhe wu di");
    }
}
new RedisAction().test();